package com.xiaoxx.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxx.mapper.ChatMenuMapper;
import com.xiaoxx.model.dto.chat.ChatMenuDto;
import com.xiaoxx.model.dto.chat.ChatMenuQueryDto;
import com.xiaoxx.model.entity.chat.ChatMenu;
import com.xiaoxx.model.vo.chat.ChatMenListVo;
import com.xiaoxx.service.ChatMenuService;
import com.xiaoxx.utils.BeanDtoVoUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author HX
 * @since 2023-07-19
 */
@Service
public class ChatMenuServiceImpl extends ServiceImpl<ChatMenuMapper, ChatMenu> implements ChatMenuService {

    @Override
    public String addChatMenu(ChatMenuDto chatMenuDto) {
        ChatMenu chatMenu = chatMenuDto.convert(ChatMenu.class);
        save(chatMenu);
        return chatMenu.getId();
    }

    @Override
    public List<ChatMenListVo> getListByUserId(ChatMenuQueryDto chatMenuQueryDto) {
        List<ChatMenu> page = lambdaQuery()
                .eq(ChatMenu::getUserId, chatMenuQueryDto.getUserId())
                .like(StringUtils.hasLength(chatMenuQueryDto.getChatMenuName()), ChatMenu::getChatMenuName, chatMenuQueryDto.getChatMenuName())
                .orderByDesc(ChatMenu::getCreateTime)
                .list();
        return BeanDtoVoUtil.listVo(page, ChatMenListVo.class);
    }

    @Override
    public Boolean updChatMenu(ChatMenuDto chatMenuDto) {
        return updateById(chatMenuDto.convert(ChatMenu.class));
    }
}
